package model;

import javax.persistence.*;

@Entity
@Table(name="Player")
public class Player {
	private int lastAction;
	private long x;
	private long y;
	private long z;
	private String name;
	@Id private String login;
	private String passwd;
	private String email;
		
	public long getX() {
		return x;
	}

	public long getY() {
		return y;
	}

	public long getZ() {
		return z;
	}
	
	public String getName() {
		return name;
	}

	public String getLogin() {
		return login;
	}

	public String getPasswd() {
		return passwd;
	}

	public String getEmail() {
		return email;
	}

	public Player(String name2, String login2, String passwd2, String email2) {
		this.name = name2;
		this.login = login2;
		this.passwd = passwd2;
		this.email = email2;
	}

	public int getLastAction() { return lastAction; }

	public void lastActionDecrease() {
		lastAction--;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public void setPass(String passwd) {
		this.passwd = passwd;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public boolean save() {
		try {
			EntityManager em = Persistence.createEntityManagerFactory("defaultPersistenceUnit").createEntityManager();
			em.getTransaction().begin();
			em.persist(this);
			em.getTransaction().commit();
		} catch (Exception e) {
			System.out.println("fail " +e.getMessage());
			return false;
		}
		return true;
	}

	public void setPosition(long x, long y, long z) {
		this.x = x;
		this.y =y;
		this.z  = z;
	}
}
